mothra: cleanup, fix memory leak in libpanel

This commit is contained in:
cinap_lenrek 2011-09-05 18:36:58 +02:00
parent e159e8e54a
commit c1d9d6e538
5 changed files with 17 additions and 12 deletions

View file

@ -128,6 +128,7 @@ Point pl_boxsize(Point interior, int state){
case FRAME:
return addpt(interior, Pt(4*FWID+2*SPACE, 4*FWID+2*SPACE));
}
return Pt(0, 0);
}
void pl_interior(int state, Point *ul, Point *size){
switch(state){

View file

@ -89,7 +89,10 @@ void pl_childspaceentry(Panel *p, Point *ul, Point *size){
USED(p, ul, size);
}
void pl_freeentry(Panel *p){
free(((Entry *)p->data)->entry);
Entry *ep;
ep = p->data;
free(ep->entry);
ep->entry = ep->eent = 0;
}
void plinitentry(Panel *v, int flags, int wid, char *str, void (*hit)(Panel *, char *)){
int elen;
@ -106,13 +109,11 @@ void plinitentry(Panel *v, int flags, int wid, char *str, void (*hit)(Panel *, c
v->free=pl_freeentry;
elen=100;
if(str) elen+=strlen(str);
if(ep->entry==nil)
ep->entry=pl_emalloc(elen+SLACK);
ep->eent=ep->entry+elen;
if(str)
strcpy(ep->entry, str);
else ep->entry[0]='\0';
strecpy(ep->entry, ep->eent, str ? str : "");
ep->entp=ep->entry+strlen(ep->entry);
/* strcat(ep->entry, "◀"); */
ep->hit=hit;
v->kind="entry";
}

View file

@ -6,7 +6,7 @@
#include "pldefs.h"
void *pl_emalloc(int n){
void *v;
v=malloc(n);
v=mallocz(n, 1);
if(v==0){
fprint(2, "Can't malloc!\n");
exits("no mem");

View file

@ -951,7 +951,7 @@ void paste(Panel *p){
fd=open("/dev/snarf", OREAD);
strncpy(buf, plentryval(p), sizeof(buf));
len=strlen(buf);
n=read(fd, buf+len, 1023-len);
n=read(fd, buf+len, sizeof(buf)-len-1);
if(n>0){
buf[len+n]='\0';
plinitentry(cmd, PACKE|EXPAND, 0, buf, docmd);
@ -960,7 +960,7 @@ void paste(Panel *p){
close(fd);
}
void hit3(int button, int item){
char name[100], *home;
char name[NNAME], *home;
Panel *swap;
int fd;
USED(button);

View file

@ -35,10 +35,13 @@ struct Fontdata{
"lucidasans/typeunicode.16", 0, 0,
};
Fontdata *pl_whichfont(int f, int s){
char name[100];
char name[NNAME];
assert(f >= 0 && f < 4);
assert(s >= 0 && s < 4);
if(fontlist[f][s].font==0){
snprint(name, sizeof(name), "/lib/font/bit/%s.font",
fontlist[f][s].name);
snprint(name, sizeof(name), "/lib/font/bit/%s.font", fontlist[f][s].name);
fontlist[f][s].font=openfont(display, name);
if(fontlist[f][s].font==0) fontlist[f][s].font=font;
fontlist[f][s].space=stringwidth(fontlist[f][s].font, "0");